package IOStreamStudy.outPutstream;

import org.junit.Test;

import java.io.FileOutputStream;
import java.io.IOException;

public class fileOutPutStreamDemo {


    @Test
    // 写入一个字符
    public void fileOutPutStream() throws IOException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\e.txt";
        FileOutputStream fileOutputStream = new FileOutputStream(filePath);
        fileOutputStream.write('H');// 会自动把字符转化成byte不是  ""  ""是字符串
        fileOutputStream.close();
    }

    @Test
    public void fileOutPutStream02() throws IOException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn\\usts\\edu\\IOStreamStudy\\e.txt";
        FileOutputStream fileOutputStream = new FileOutputStream(filePath,true);// 第二个参数代表是否追加
        String msg = "hello world";

        //fileOutputStream.write(msg.getBytes(),0,8);// 从0开始写到第八个byte(字节)
        fileOutputStream.write(msg.getBytes());// 默认写完
        fileOutputStream.close();
    }
}
